package com.hzlj.position.locate.dao;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fz.common.base.converter.QueryWrapperConverterPlus;
import com.fz.common.base.dto.PageParamDTO;
import com.fz.common.base.dto.QueryPageResultDTO;
import com.hzlj.position.locate.common.dto.abnMissingJzry.AbnMissingJzryQueryParamDTO;
import com.hzlj.position.locate.common.dto.abnMissingJzry.AbnMissingJzryQueryResultDTO;
import com.hzlj.position.locate.common.enums.AbnMissingCheck;
import com.hzlj.position.locate.common.enums.AbnMissingCheckStatus;
import com.hzlj.position.locate.common.model.AbnMissingJzry;
import com.hzlj.position.locate.common.model.AbnMissingJzryNotice;
import com.hzlj.position.locate.mapper.AbnMissingJzryMapper;
import com.hzlj.position.locate.mapper.AbnMissingJzryNoticeMapper;
import com.hzlj.sqjz.config.common.enums.HandleStatus;
import com.hzlj.sqjz.jz.common.constant.JzJoin;
import com.hzlj.sqjz.jz.common.model.JzJbxx;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 定位分析-疑似失联人员(AbnMissingJzry)表操作类
 *
 * @author makejava
 * @date 2024-06-25 14:40:45
 */
@Repository
public class AbnMissingJzryDao extends ServiceImpl<AbnMissingJzryMapper, AbnMissingJzry> {
    @Resource
    private AbnMissingJzryMapper abnMissingJzryMapper;
    @Resource
    private AbnMissingJzryNoticeMapper abnMissingJzryNoticeMapper;

    /**
     * 修改数据
     */
    public boolean updateCheck(String id,
                               String step,
                               AbnMissingCheck check,
                               AbnMissingCheckStatus checkStatus,
                               HandleStatus handleStatus,
                               Date reportTime) {
        LambdaUpdateWrapper<AbnMissingJzry> queryWrapper = new UpdateWrapper<AbnMissingJzry>().lambda()
                .set(AbnMissingJzry::getMissingCheck, check.getStatus())
                .set(AbnMissingJzry::getMissingCheckStatus, checkStatus.getStatus())
                .set(AbnMissingJzry::getHandleStatus, handleStatus.getStatus())
                .set(ObjectUtil.isNotEmpty(step), AbnMissingJzry::getStep, step)
                .set(ObjectUtil.isNotEmpty(reportTime), AbnMissingJzry::getReportTime, reportTime)
                .eq(AbnMissingJzry::getId, id);
        return this.update(queryWrapper);
    }

    /**
     * 查询列表：不分页
     */
    public List<AbnMissingJzryQueryResultDTO> listAbnMissingJzry(AbnMissingJzryQueryParamDTO dto) {
        return QueryWrapperConverterPlus.of(abnMissingJzryMapper)
                .innerJoin(JzJbxx.class, JzJoin.jz(AbnMissingJzry::getJzId))
                .mappingMany(Boolean.TRUE.equals(dto.getWithNotice()),abnMissingJzryNoticeMapper, AbnMissingJzryNotice::getMissingId, AbnMissingJzryQueryResultDTO::getId, AbnMissingJzryQueryResultDTO::getNotices, null)
                .list(AbnMissingJzryQueryResultDTO.class, dto);
    }

    /**
     * 查询列表：分页
     */
    public QueryPageResultDTO<AbnMissingJzryQueryResultDTO> pageAbnMissingJzry(AbnMissingJzryQueryParamDTO dto, PageParamDTO page) {
        return QueryWrapperConverterPlus.of(abnMissingJzryMapper)
                .innerJoin(JzJbxx.class, JzJoin.jz(AbnMissingJzry::getJzId))
                .page(AbnMissingJzryQueryResultDTO.class, dto, page);
    }
}

